<%@ page language="java" contentType="text/html; charset=windows-1255" pageEncoding="windows-1255"%>
<%@ include file="admin_Header.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="http://code.jquery.com/mobile/latest/jquery.mobile.min.css" rel="stylesheet" type="text/css" />
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script src="http://code.jquery.com/mobile/latest/jquery.mobile.min.js"></script>
<title>Add Supermarket</title>
</head>
<body>
<%
	if ((request.getParameter("supermarketName") != null) &&
	    (request.getParameter("supermarketBranch") != null) &&
	    (request.getParameter("supermarketLatitude") != null) &&
	    (request.getParameter("supermarketLongitude") != null))
	{
		out.println("Adding supermarket " + request.getParameter("supermarketName"));
		try
		{
		    String supermarketName = request.getParameter("supermarketName");
			String supermarketBranch = request.getParameter("supermarketBranch");
			Double supermarketLatitude = Double.parseDouble(request.getParameter("supermarketLatitude"));
			Double supermarketLongitude	= Double.parseDouble(request.getParameter("supermarketLongitude"));
			Supermarket supermarket = new Supermarket();
			supermarket.setSupermarketName(supermarketName);
			supermarket.setSupermarketBranch(supermarketBranch);
			supermarket.setSupermarketLocationLatitude(supermarketLatitude);
			supermarket.setSupermarketLocationLongitude(supermarketLongitude);
			iproducts.AddSupermarket(supermarket);
			Supermarket verifySupermarket = iproducts.FindSupermarket(supermarket.getSupermarketName(), supermarket.getSupermarketBranch(), supermarket.getSupermarketLocationLatitude(), supermarket.getSupermarketLocationLongitude());
			if ((verifySupermarket.getSupermarketName().equals(supermarketName)) &&
				(verifySupermarket.getSupermarketBranch().equals(supermarketBranch)) &&
				(verifySupermarket.getSupermarketLocationLatitude().equals(supermarketLatitude)) &&
				(verifySupermarket.getSupermarketLocationLongitude().equals(supermarketLongitude)))
			{
				out.println("\nSupermarket added successfully");
			}
			else
			{
				out.println("\nSomething went wrong, please check");
			}
		}
		catch(Exception e)
		{
			throw new Exception("Error in connecting to database, please contact your administrator");
		}
	}
%>
<div data-role="page">
	<div data-role="header" align="center">
		<h1>Products Compare<br>Application</h1>
		<a href='#' class='ui-btn-left' data-icon='arrow-l' onclick="history.back(); return false">Back</a><a href="#admin_firstpage">Home</a>
	</div>
	
	<div data-role="content" align="center">
		<form action="admin_AddSupermarket.jsp" method="post">
			<div data-role="fieldcontain">
				<label for="supermarketName">Supermarket Name:</label>
				<input type="text" name="supermarketName" id="supermarketName" value=""/>
			</div>
			<div data-role="fieldcontain">
				<label for="supermarketBranch">Supermarket Branch:</label>
				<input type="text" name="supermarketBranch" id="supermarketBranch" value=""/>
			</div>
			<div data-role="fieldcontain">
				<label for="supermarketLatitude">Supermarket Latitude:</label>
				<input type="text" name="supermarketLatitude" id="supermarketLatitude" value=""/>
			</div>
			<div data-role="fieldcontain">
				<label for="supermarketLongitude">Supermarket Longitude:</label>
				<input type="text" name="supermarketLongitude" id="supermarketLongitude" value=""/>
			</div>
			<button type="submit" data-theme="e">Submit</button>
		</form>
	</div>
</div>
</body>
</html>